<template>
  <div>
    <div class="personal-info-box">
      <div class="triangle"></div>
      <div class="team-name">{{ teamInfo.teamName }}</div>
      <div class="team-img">
        <img :src="teamInfo.teamImg" alt="" />
      </div>
      <div class="team-city">城市:{{ teamInfo.city }}</div>
      <div class="team-stadium">主场:{{ teamInfo.stadiums }}</div>
      <div class="bottom-tab-bar">
        <div class="personal-info-el-tabs">
          <el-tabs v-model="activeName">
            <el-tab-pane label="球队信息" name="teamInfo" />
            <el-tab-pane label="球队阵容" name="teamSquad" />
            <el-tab-pane label="指标排名" name="metricsRank" />
            <el-tab-pane label="战术表现" name="tacticalPerformance" />
          </el-tabs>
        </div>
        <div class="selector-season">
          <el-select
            v-model="season"
            @focus="setMinWidthEmpty"
            style="width:150px"
            placeholder="请选择赛季"
          >
            <el-option
              v-for="item in options"
              :key="item.season"
              :label="item.label"
              :value="item.season"
            >
            </el-option>
          </el-select>
        </div>
      </div>
    </div>
    <div>
      <TeamInfo
        :season="season"
        :teamId="teamId"
        v-show="activeName === 'teamInfo'"
      />
      <TeamSquad
        :season="season"
        :teamId="teamId"
        v-show="activeName === 'teamSquad'"
      />
      <MetricsRank
        :season="season"
        :teamId="teamId"
        v-show="activeName === 'metricsRank'"
      />
      <TacticalPerformance v-show="activeName === 'tacticalPerformance'" />
    </div>
  </div>
</template>

<script>
import axios from "axios";
import MyTransition from "../transition/MyTransition";
import mixin from "../../mixin/mixin";
import TeamInfo from "./teamInfo/TeamInfo";
import TeamSquad from "./teamSquad/TeamSquad";
import MetricsRank from "./metricsRank/MetricsRank";
import TacticalPerformance from "./tacticalPerformance/TacticalPerformance";
export default {
  name: "SingleTeam",
  mixins: [mixin],
  components: {
    MyTransition,
    TeamInfo,
    TeamSquad,
    MetricsRank,
    TacticalPerformance,
  },
  data() {
    return {
      selectOptionWidth: "",
      activeName: "teamInfo",
      teamId: null,
      season: "2019赛季",
      options: [
        {
          season: "2019赛季",
          label: "2019赛季",
        },
        {
          season: "2018赛季",
          label: "2018赛季",
        },
        {
          season: "2017赛季",
          label: "2017赛季",
        },
        {
          season: "2016赛季",
          label: "2016赛季",
        },
      ],
      teamInfo: {},
    };
  },
  methods: {
    async getTeamInfo(seasonId, teamId) {
      const { data } = await axios.get(
        `http://8.141.159.127:3000/api/v1/teams/teamInfor/${seasonId}/${teamId}`
      );
      this.teamInfo = data[0];
    },
  },
  beforeRouteEnter(to, from, next) {
    const { teamId } = to.params;
    console.log("Enter首次进入:", teamId);
    next((vm) => {
      vm.teamId = parseInt(teamId);
      vm.getTeamInfo(2019, teamId);
    });
  },
  beforeRouteUpdate(to, from, next) {
    const { teamId } = to.params;
    console.log("Enter复用进入:", teamId);
    this.teamId = parseInt(teamId);
    this.getTeamInfo(2019, teamId);
    this.activeName = "teamInfo";
    next();
  },
};
</script>

<style scoped>
.personal-info-box {
  position: relative;
  background-color: #f1f6f9;
  width: 1440px;
  height: 294px;
  margin: auto;
}
.triangle {
  border-style: solid;
  border-width: 29px;
  border-color: #65d6c1 transparent transparent #65d6c1;
  width: 0;
  height: 0;
}
.team-name {
  position: absolute;
  top: 8%;
  left: 17%;
  text-align: center;
  font-size: 77px;
  letter-spacing: 10px;
  width: 60%;
  height: 50%;
  line-height: 147px;
  color: #16c79a;
  font-weight: bold;
  /*background-color: navy;*/
  /*user-select: none;*/
}
.player-info-item > div:nth-child(1) {
  width: 80px;
  /*background-color: red;*/
}
.player-info-item > div:nth-child(2) {
  line-height: 30px;
  width: 140px;
  height: 30px;
  /*background-color: blue;*/
}
.team-img {
  position: absolute;
  top: 15%;
  left: 3%;
  width: 200px;
  height: 250px;
  z-index: 2;
  /*background-color: red;*/
}
.team-img > img {
  width: 100%;
  height: 100%;
  /*border-radius: 50%;*/
}
.team-city {
  position: absolute;
  bottom: 105px;
  left: 75%;
  width: 200px;
  height: 50px;
  /*background-color: red;*/
  color: #16c79a;
  font-size: 30px;
  line-height: 50px;
  font-weight: bold;
  text-align: left;
}
.team-stadium {
  position: absolute;
  bottom: 50px;
  left: 75%;
  width: 350px;
  height: 50px;
  /*background-color: red;*/
  color: #16c79a;
  font-size: 30px;
  line-height: 50px;
  font-weight: bold;
  text-align: left;
}
.bottom-tab-bar {
  position: absolute;
  bottom: 0;
  text-align: center;
  font-size: 30px;
  width: 100%;
  height: 57px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background-color: #194568;
}
.personal-info-el-tabs {
  margin-top: 5px;
  margin-left: 300px;
}
.selector-season /deep/ .el-input {
  width: 80%;
}
.selector-season /deep/ .el-input__inner {
  height: 30px;
}
.selector-season /deep/ .el-input__suffix {
  top: 6px;
}
.personal-info-el-tabs /deep/ .el-tabs__item {
  color: white;
  font-size: 20px;
  font-weight: bold;
}
.personal-info-el-tabs /deep/ .el-tabs__nav-wrap::after {
  height: 0;
}
.personal-info-el-tabs /deep/ .el-tabs__active-bar {
  height: 3px;
  background-color: #16c79a;
}
.personal-info-el-tabs /deep/ .el-tabs__item:hover {
  color: #16c79a;
}
.personal-info-el-tabs /deep/ .el-tabs__item.is-active {
  color: #16c79a;
}
</style>
